<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button @click="handleAdd" size="mini">添加下级</el-button>
        <el-button @click="handleEdit" size="mini">编辑</el-button>
        <el-button @click="handleDelete" size="mini">删除</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="序号" type="index" :index="indexMethod" width="80" />
      <el-table-column label="费用类别" prop="roleKey" />
      <el-table-column label="父级节点" prop="roleKey" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 新增编辑弹窗 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="费用类别">
          <el-input v-model="form.roleName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="父级节点">
          <el-select v-model="form.q" placeholder="请选择" style="width: 100%;">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="open=false">取 消</el-button>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listRole } from "@/api/system/role";

export default {
  data() {
    return {
      // 下拉数据
      options: [],
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 新增编辑弹窗
      title: '新增',
      open: false,
      form: {},
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 序号计算
    indexMethod(index) {
      return (this.queryParams.pageNum- 1) * this.queryParams.pageSize + index + 1;
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      listRole(this.addDateRange(this.queryParams)).then(response => {
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 重置表单
    reset() {
      this.form = {}
    },
    // 新增
    handleAdd() {
      this.reset()
      this.title = '新增'
      this.open = true
    },
    // 编辑
    handleEdit() {
      this.reset()
      this.title = '编辑'
      this.open = true
    },
    // 删除按钮
    handleDelete() {
      this.$modal
        .confirm("确定要删除该记录吗？")
        .then(() => {
          
        })
    },
    // 新增编辑弹窗确定
    submitForm() {

    }
  }
};
</script>
